#include "Parser.h"

enum ParserState {
    SBegin,
    SPackageName,
    SPackageContent,
    SPackageItem,
    SPackageImport,
    SPackageImportEnd,
    SPackageEnum,
    SPackageEnumContent,
    SPackageEnumItem,
    SPackageEnumEnd,
    SPackageInterface,
    SPackageInterfaceSuper,
    SPackageInterfaceSuperEnd,
    SPackageInterfaceContent,
    SPackageInterfaceItem,
    SPackageClass,
    SPackageFunction

};

Parser::Parser()
{
	//ctor
}

Parser::~Parser()
{
	//dtor
}

Package *parserToken ( Lexer *plex )
{
	Package *package;
	package = 0;
	ParserState state;
	state = SBegin;
	Token *ptoken;
	ptoken = plex->getKeyToken();
	while ( ptoken ) {
		switch ( state ) {
				//状态0 文件开始，只能是包定义
			case SBegin: {
					switch ( ptoken->type ) {
						case TokenKey_Package: {
								state = SPackageName;
								if ( package == 0 ) {
									package = new Package();
									break;
								} else {
									//出错
									return 0;
								}
							}
						default: {
								//出错提示
								return 0;
							}
					}
					break;
				}
				//状态1 读取包名字
			case SPackageName: {
					switch ( ptoken->type ) {
						case TokenKey_Package:
						case Token_Variable: {
								//package->setName(ptoken->pstr);
								state = SPackageContent;
								break;
							}
						default: {
								return 0;
							}
					}
					break;
				}
				//准备开始读取包内容
			case SPackageContent: {
					switch ( ptoken->type ) {
						case TokenOpt_End: {
								//出错
								return 0;
							}
						case TokenOpt_BlockStart: {
								state = SPackageItem;
								break;
							}
						default: {
								return 0;
							}
					}
					break;
				}
				//包内容实际读取
			case SPackageItem: {
					switch ( ptoken->type ) {
						case TokenOpt_BlockEnd: {
								//包读取结束，后面符号
								state = SBegin;
								break;
							}
						case TokenKey_Import: {
								state = SPackageImport;
								break;
							}
						case TokenKey_Enum: {

							}
						case TokenKey_Public_Enum: {

							}
						case TokenKey_Private_Enum: {

							}
						case TokenKey_Interface: {

							}
						case TokenKey_Public_Interface: {

							}
						case TokenKey_Private_Interface: {

							}
						case TokenKey_Class: {

							}
						case TokenKey_Public_Class: {

							}
						case TokenKey_Private_Class: {

							}
						default: {
								//出错信息
								return 0;
							}


					}
					break;
				}
				//读取import信息
			case SPackageImport: {
					switch ( ptoken->type ) {
						case Token_Variable: {
								state = SPackageImportEnd;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageImportEnd: {
					switch ( ptoken->type ) {
						case TokenOpt_Get: {
								state = SPackageImport;
								break;
							}
						case TokenOpt_End: {
								state = SPackageItem;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}

			case SPackageEnum: {
					switch ( ptoken->type ) {
						case Token_Variable: {
								state = SPackageEnumContent;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageEnumContent: {
					switch ( ptoken->type ) {
						case TokenOpt_End: {
								state = SPackageItem;
								break;
							}
						case TokenOpt_BlockStart: {
								state = SPackageEnumItem;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageEnumItem: {
					switch ( ptoken->type ) {
						case Token_Variable: {
								state = SPackageEnumEnd;
								break;
							}
						case TokenOpt_BlockEnd: {
								state = SPackageItem;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageEnumEnd: {
					switch ( ptoken->type ) {
						case TokenOpt_End: {
								state = SPackageEnumItem;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}

			case SPackageInterface: {
					switch ( ptoken->type ) {
						case Token_Variable: {
								state = SPackageInterfaceContent;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageInterfaceContent: {
					switch ( ptoken->type ) {
						case TokenOpt_End: {
								state = SPackageItem;
								break;
							}
						case TokenOpt_BlockStart: {
								state = SPackageInterfaceItem;
								break;
							}
						case TokenOpt_Extends: {
								state = SPackageInterfaceSuper;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageInterfaceSuper: {
					switch ( ptoken->type ) {
						case TokenKey_Package: {

							}
						case Token_Variable: {
								state = SPackageInterfaceSuperEnd;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageInterfaceSuperEnd: {
					switch ( ptoken->type ) {
						case TokenOpt_Get: {
								state = SPackageInterfaceSuper;
								break;
							}
						case TokenOpt_BlockStart: {
								state = SPackageInterfaceItem;
								break;
							}
						case Token_Variable: {

								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;
				}
			case SPackageInterfaceItem: {
					switch ( ptoken->type ) {
						case TokenKey_Function: {
								state = SPackageFunction;
								break;
							}
						case TokenOpt_End: {
								break;
							}
						case TokenOpt_BlockEnd: {
								state = SPackageItem;
								break;
							}
						default: {
								//出错信息
								return 0;
							}
					}
					break;

				}

			case SPackageClass: {

				}

			default: {

				}

		}
		ptoken = plex->getKeyToken();
	}
}
